<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
</html>
<script>
    function fn (obj) {
        var obj2 = (Array.isArray(obj)? [] : {} )
        for ( var index in obj ){
            if(typeof obj[index] == 'object'){
                obj2[index] = fn(obj[index])
            }
            else{
                obj2[index] = obj[index]
            }
        } 
        return obj2
    }
    
    var obj2 = {name : 123 , age : 432}
   
    var res = fn(obj2)
    console.log(res);
    obj2.name = 222
</script>